part of 'component.dart';

class MenuItemView extends StatelessWidget {
  const MenuItemView(
      {Key? key,
      required this.icon,
      required this.title,
      this.color,
      this.padding,
      this.width,
      this.newsCount = 0,
      this.spacing,
      this.onTap})
      : super(key: key);
  final Widget icon;
  final Widget title;
  final EdgeInsetsGeometry? padding;
  final VoidCallback? onTap;
  final double? width;
  final double? spacing;
  final int newsCount;
  final Color? color;
  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: onTap,
      child: Container(
        color: color,
        padding: padding,
        width: width,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            icon,
            SizedBox(
              height: spacing ?? 10.r,
            ),
            title
          ],
        ),
      ),
    );
  }
}

class RedContainer extends StatelessWidget {
  const RedContainer({
    Key? key,
    required this.child,
    required this.childSize,
    this.redCount = 0,
    this.offx,
    this.height,
    this.fontSize,
    this.redSize,
  }) : super(key: key);
  final Widget child;
  final double childSize;
  final int redCount;
  final double? offx;
  final double? height;
  final double? fontSize;
  final double? redSize;
  @override
  Widget build(BuildContext context) {
    var _height = height ?? childSize;
    var _offx = offx ?? 4.r;
    var _redStr = '$redCount';
    var _fontSize = fontSize ?? font10;
    var _offy = 3.r;
    if (redCount > 99) {
      _redStr = '99+';
    }
    if (redCount > 9) {
      _fontSize -= 2.r;
    }
    var _redHeight = _fontSize + 5.r;
    return SizedBox(
      height: _height + _offy,
      width: childSize + _offx,
      child: Stack(
        children: [
          Positioned(
            top: _offy,
            right: _offx,
            child: child,
          ),
          Positioned(
            right: 0,
            child: Visibility(
              visible: redCount > 0,
              child: ClipRRect(
                borderRadius: BorderRadius.circular(_redHeight / 2),
                child: Container(
                  height: _redHeight,
                  constraints: BoxConstraints(minWidth: _redHeight),
                  padding: EdgeInsets.symmetric(horizontal: 3.r),
                  alignment: Alignment.center,
                  decoration: const BoxDecoration(
                    color: ColorsUtil.red,
                  ),
                  child: Text(
                    _redStr,
                    style: pfMediumStyle(
                        color: ColorsUtil.white, fontSize: _fontSize),
                  ),
                ),
              ),
            ),
          )
        ],
      ),
    );
  }
}
